package com.joekai.view_demo.dot_loading;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @author joekai
 */
public class DotView extends View {
    private final Paint mPaint;
    private int mColor;
    public DotView(Context context) {
        this(context,null);
    }

    public DotView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public DotView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr,0);
    }

    public DotView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        // 画背景圆形 三个参数  cx cy  半径 画笔
        int cx = getWidth()/2;
        int cy = getHeight()/2;
        canvas.drawCircle(cx,cy,cx,mPaint);
    }

    /**
     *
     * @param color 颜色
     */
    public void exchangeColor(int color){
        mColor = color;
        mPaint.setColor(color);
        invalidate();
    }
    /**
     * 获取当前的颜色
     * @return  颜色
     */
    public int getColor() {
        return mColor;
    }
}
